package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.service.ValidateCodeService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/validateCode")
@ResponseBody
@Controller
public class ValidateCodeController {

    @Reference
    private ValidateCodeService validateCodeService;

    @RequestMapping("/sendCode")
    public Result sendCode(String telephone){
        boolean flag=false;
        String message=null;
        try {
            validateCodeService.sendCode(telephone);
            flag=true;
            message= MessageConstant.SEND_VALIDATECODE_SUCCESS;
        } catch (Exception e) {
            message= MessageConstant.SEND_VALIDATECODE_FAIL;
            e.printStackTrace();
        }
        return new Result(flag,message);
    }

    @RequestMapping("/loginCode")
    public Result loginCode(String telephone){
        boolean flag=false;
        String message=null;
        try {
            validateCodeService.loginCode(telephone);
            flag=true;
            message= MessageConstant.SEND_VALIDATECODE_SUCCESS;
        } catch (Exception e) {
            message= MessageConstant.SEND_VALIDATECODE_FAIL;
            e.printStackTrace();
        }
        return new Result(flag,message);
    }
}
